package com.nowcoder.community.controller;

import com.nowcoder.community.annotation.RestLoginRequire;
import com.nowcoder.community.service.FollowService;
import com.nowcoder.community.util.HostHolder;
import com.nowcoder.community.util.JsonBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("follow")
public class FollowController {

    @Autowired
    FollowService followService;

    @Autowired
    HostHolder hostHolder;

    @RestLoginRequire
    @PostMapping("/user")
    public JsonBody followUser(int userId) {
        followService.followUser(hostHolder.getUser().getId(), userId);
        return JsonBody.ok("关注成功!");
    }

    @RestLoginRequire
    @PostMapping("/cancel/user")
    public JsonBody unfollowUser(int userId) {
        followService.unfollowUser(hostHolder.getUser().getId(), userId);
        return JsonBody.ok("已取关！");
    }
}
